import { Component, ViewEncapsulation, ViewChild, OnInit } from '@angular/core';
import { MdSidenav } from '@angular/material';
import { PageTitle } from "./page-title"
import { Router } from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: "./app.component.html",
  styleUrls: [ "./app.component.css" ],
  encapsulation: ViewEncapsulation.None,
})
export class AppComponent implements OnInit {
  @ViewChild(MdSidenav) sidenav: MdSidenav;

  constructor(private pageTitle: PageTitle, private router: Router) { }

  ngOnInit(): void {
    this.router.events.subscribe(() => {
      if (this.isScreenSmall()) {
        this.sidenav.close();
      }
    })
  }

  getBack(): string {
    return this.pageTitle.back
  }

  isScreenSmall(): boolean {
    return window.matchMedia(`(max-width: 1280px)`).matches;
  }
}
